package com.concurrent.queue.demo1;

import java.util.ArrayList;
import java.util.List;

public class JuiceMachineImpl implements Runnable, JuiceMachine {

	private List<Juice> juices = new ArrayList<Juice>();

	private JuiceShop juiceShop;

	public void run() {
		while (true) {
			try {
				for (int i = 0; i < 10; i++) {
					Juice j = new Juice();
					juices.add(j);
				}
				System.out.println("生产果汁:" + juices.size());
				juiceShop.putJuices(getNewJuices());
				System.out.println("完成送货");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public List<Juice> getNewJuices() {
		List<Juice> subList = new ArrayList<Juice>(juices);
		juices.clear();
		return subList;
	}

	public void setJuiceShop(JuiceShop juiceShop) {
		this.juiceShop = juiceShop;
	}

}
